<template>
	<view>
		<view class="wrapper flex-row row-column row-center row-middle">
			<view class="scan">
				<u-icon name="scan" color="#26c68a" size="400"></u-icon>
			</view>
			<view class="btn" @click="oldScanCode">请扫描灯体上二维码</view>
			<view class="tip">如果灯体二维码扫不出来，联系车灯师客服，提供数字码</view>
			<view class="input">
				<u--input  placeholder="请输入数字唯一码" border="surround" :customStyle="'padding: 20rpx'" v-model="oldCode"></u--input>
			</view>
			<view class="btn-confirm" @click="confirm">确认</view>
		</view>
	</view>
</template>


<script>
	import {
		toLogin,
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				newCode: '',
				oldCode: ''
			}

		},

		computed: mapGetters(['isLogin', 'uid']),

		onLoad() {
			if (this.isLogin == false) {
				toLogin();
			}
		},

		onShow() {

		},

		methods: {
			/**
			 * 扫描旧的
			 */
			oldScanCode() {
				let that = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					scanType: ["qrCode"],
					success: (res) => {
						if (res.result) {
							let data = [], flowCode = '';
							data = res.result.split("=");
							if(data.length > 1) {
								flowCode = data[1];
							} else {
								flowCode = data[0];
							}
							that.oldCode = flowCode;
						} else {
							return that.$util.Tips({
								title: '请重新扫描'
							})
						}
					},
					fail: (res) => {
						that.$util.Tips({
							title: '未识别到二维码'
						})
					}
				})
			},
			
			/**
			 * 确认
			 */
			confirm() {
				let that = this;
				if (!that.oldCode) {
					return that.$util.Tips({
						title: "请扫描灯体二维码"
					})
				}
				that.$util.Tips('/pages/users/aftermarket_detail/index?type=0&oldCode=' + that.oldCode)
			},

		}
	}
</script>

<style>
	page {
		background: #FFF;
	}

	.wrapper {
		position: relative;
		margin: 20rpx;
	}
	
	.wrapper .scan {
		margin: 40rpx 0;
	}
	
	.wrapper .tip {
		color: #737373;
		font-size: 24rpx;
		margin: 50rpx 0 40rpx;
	}
	
	.wrapper .btn {
		padding: 25rpx;
		background-color: #26c68a;
		width: 70%;
		/* height: 40rpx; */
		/* line-height: 40rpx; */
		color: #fff;
		text-align: center;
		font-size: 32rpx;
	}
	
	.wrapper .input {
		width: 80%;
		box-sizing: border-box;
	}
	
	.wrapper .btn-confirm {
		border: 1px solid #c3c6cd;
		color: #737373;
		padding: 20rpx 40rpx;
		margin-top: 50rpx;
		border-radius: 6rpx;
	}
</style>